//////#define _CRT_SECURE_NO_WARNINGS 1
//////#include <iostream>
//////#include<cstring>
//////#include <cstring>
//////using namespace std;
//////class CPeople
//////{
//////protected:
//////    string name;
//////    char sex;
//////    int age;
//////public:
//////    CPeople() {}
//////    CPeople(string n, char s, int a) :name(n), sex(s), age(a) {}
//////    void print() 
//////    {
//////        cout << "People:" << endl;
//////        printP();
//////        cout << endl;
//////    }
//////    void printP()
//////    { 
//////        cout << "Name: " << name << endl << "Sex: " << sex << endl << "Age: " << age << endl;
//////    }
//////};
//////
//////
//////class CTeacher : public virtual CPeople
//////{
//////protected:
//////    char position[16],
//////        department[16];
//////public:
//////    CTeacher() {}
//////    CTeacher(CPeople p, char* po, char* d) :CPeople(p) {
//////        strcpy(position, po);
//////        strcpy(department, d);
//////    }
//////    void print() {
//////        cout << "Teacher:" << endl;
//////        printP();
//////        printT();
//////        cout << endl;
//////    }
//////    void printT() {
//////        cout << "Position: " << position << endl << "Department: " << department << endl;
//////    }
//////};
//////
//////class CStudent : public virtual CPeople
//////{
//////protected:
//////    char no[11];
//////    float score;
//////public:
//////    CStudent() {}
//////    CStudent(CPeople p, char* n, float s) :CPeople(p), score(s) { strcpy(no, n); }
//////    void print() {
//////        cout << "Student:" << endl;
//////        printP();
//////        printS();
//////        cout << endl;
//////    }
//////    void printS() { cout << "No.: " << no << endl << "Score: " << score << endl; }
//////};
//////
//////
//////
//////class CGradOnWork : public CStudent, public CTeacher
//////{
//////    char direction[16],
//////        tutor[16];
//////public:
//////    CGradOnWork() {}
//////    CGradOnWork(CPeople p, CStudent s, CTeacher t, char* d, char* tu) :CPeople(p), CStudent(s), CTeacher(t) {
//////        strcpy(direction, d);
//////        strcpy(tutor, tu);
//////    }
//////    void print() {
//////        cout << "GradOnWork:" << endl;
//////        printP();
//////        printS();
//////        printT();
//////        cout << "Direction: " << direction << endl << "Tutor: " << tutor << endl;
//////    }
//////};
//////
//////int main()
//////{
//////    string name;
//////    int age;
//////    float score;
//////    char sex, no[11], pos[16], dep[16], dir[16], tut[16];
//////    cin >> name >> sex >> age;
//////    CPeople people(name, sex, age);
//////    people.print();
//////    cin >> no >> score;
//////    CStudent student(people, no, score);
//////    student.print();
//////    cin >> pos >> dep;
//////    CTeacher teacher(people, pos, dep);
//////    teacher.print();
//////    cin >> dir >> tut;
//////    CGradOnWork grad(people, student, teacher, dir, tut);
//////    grad.print();
//////    return 0;
//////}
////
////
////
////
////#include<iostream>
////#include<cstring>
////#include<cmath>
////using namespace std;
////class VIP
////{
////public:
////	VIP(int number1, int score1)
////	{
////		number = number1;
////		score = score1;
////	}
////	int add(float m)
////	{
////		score += m;
////		return score;
////	}
////protected:
////	int number;
////	static int  score;
////};
////
////int VIP::score = 0;
////
////class Creditcard
////{
////public:
////	Creditcard(int number1, string name1, int sum1, float pay1, int score1)
////	{
////		number3 = number1;
////		name = name1;
////		sum = sum1;
////		pay = pay1;
////		score3 = score1;
////	}
////	void use(float m)
////	{
////		if (m + pay > sum)
////		{
////		}
////		else
////		{
////			pay += m;
////			score3 = score3 + m;
////		}
////	}
////	void showpay()
////	{
////		cout << pay << endl;
////	}
////	void back(float m)
////	{
////		pay -= m;
////		score3 = score3 - m;
////	}
////	int add(float m)
////	{
////		score3 = score3 + m;
////		return score3;
////	}
////protected:
////	int number3;
////	string name;
////	int sum;
////	float pay;
////	static	float score3;
////};
////
////float Creditcard::score3 = 0;
////
////class Tripcreditcard :public VIP, public Creditcard
////{
////public:
////	Tripcreditcard(int number1, int number2, string name1, int sum1, float pay1, int score1, int score2) :Creditcard(number2, name1, sum1, pay1, score2), VIP(number1, score1)
////	{
////
////	}
////	void add(float m)
////	{
////		int s1, s2, s3;
////		s1 = VIP::add(m);
////		s2 = Creditcard::add(m);
////		pay += m;
////	}
////	void change(float m)
////	{
////		int s1, s2, s3;
////		s2 = m / 2;
////		score = score + s2;
////		score3 = score3 - m;
////	}
////	void display()
////	{
////		cout << number << " ";
////		cout << score << endl;
////		cout << number3 << " " << name << " " << pay << " " << int(score3) << endl;
////	}
////
////};
////
////int main()
////{
////	int number1, number2;
////	string name1;
////	float m;
////	int sum1;
////	int t, i;
////	char a;
////	cin >> number1 >> number2 >> name1 >> sum1;
////	Tripcreditcard Tripcreditcard1(number1, number2, name1, sum1, 0, 0, 0);
////	cin >> t;
////	for (i = 0; i < t; i++)
////	{
////		cin >> a >> m;
////		if (a == 'o')
////		{
////			Tripcreditcard1.add(m);
////		}
////		else if (a == 'c')
////		{
////			Tripcreditcard1.use(m);
////		}
////		else if (a == 'q')
////		{
////			Tripcreditcard1.back(m);
////		}
////		else if (a == 't')
////		{
////			Tripcreditcard1.change(m);
////		}
////	}
////	Tripcreditcard1.display();
////	return 0;
//
////}
//
//
//#include <iostream>
//#include <string>
//#include <cmath>
//#include <iomanip>
//using namespace std;
//class shape
//{
//public:
//	virtual float area() {}
//};
//class C :public shape
//{
//protected:
//	float r;
//public:
//	C(float r1) :r(r1) {}
//	float area()
//	{
//		return 3.14 * r * r;
//	}
//};
//class S :public shape
//{
//protected:
//	float a;
//public:
//	S(float a1) :a(a1) {}
//	float area()
//	{
//		return a * a;
//	}
//
//};
//class R :public shape
//{
//protected:
//	float x;
//	float y;
//public:
//	R(float x1, float y1) :x(x1), y(y1) {}
//	float area()
//	{
//		return x * y;
//	}
//};
//void pri(shape* a)
//{
//	cout << fixed << setprecision(2) << a->area() << endl;
//
//}
//int main()
//{
//	int sum;
//	cin >> sum;
//	float r, a, x, y;
//	shape* z;
//	while (sum--)
//	{
//		cin >> r;
//		C a1(r);
//		z = &a1;
//		pri(z);
//		cin >> a;
//		S a2(a);
//		z = &a2;
//		pri(z);
//
//		cin >> x >> y;
//		R a3(x, y);
//		z = &a3;
//		pri(z);
//	}
//	return 0;
//}
//
//
//
//#include<iostream>
//using namespace std;
//class Vehicle
//{
//protected:
//    string no; 
//public:
//    Vehicle() {};
//    Vehicle(string n)
//    {
//        no = n;
//    }
//    virtual void display() = 0; 
//};
//class car :public Vehicle
//{
//private:
//    int num;
//    int weight;
//public:
//    car() {};
//    car(string no, int n, int w) :Vehicle(no)
//    {
//        num = n;
//        weight = w;
//    }
//    virtual void display()
//    {
//        cout << no << " " << num * 8 + weight * 2 << endl;
//    }
//};
//class truck :public Vehicle
//{
//private:
//    int weight;
//public:
//    truck() {};
//    truck(string n, int w) :Vehicle(n)
//    {
//        weight = w;
//    }
//    virtual void display()
//    {
//        cout << no << " " << weight * 5 << endl;
//    }
//};
//class bus :public Vehicle
//{
//private:
//    int num;
//public:
//    bus() {};
//    bus(string no, int n) :Vehicle(no)
//    {
//        num = n;
//    }
//    virtual void display()
//    {
//        cout << no << " " << num * 30 << endl;
//    }
//};
//int main()
//{
//    int t;
//    cin >> t;
//    int type;
//    string no;
//    int num, weight;
//    while (t--)
//    {
//        cin >> type;
//        cin >> no;
//        if (type == 1)
//        {
//            cin >> num >> weight;
//            car c(no, num, weight);
//            c.display();
//        }
//        else if (type == 2)
//        {
//            cin >> weight;
//            truck t(no, weight);
//            t.display();
//        }
//        else
//        {
//            cin >> num;
//            bus b(no, num);
//            b.display();
//        }
//    }
//    return 0;
//}
//

#include<iostream>
#include <cstring>
using namespace std;
class BaseAccount 
{
protected:
	char* name;
	char* account;
	int balance;
public:
	BaseAccount(char* n, char* a, int b) :balance(b)
	{
		name = new char[strlen(n) + 1];
		strcpy(name, n);
		account = new char[strlen(a) + 1];
		strcpy(account, a);
	}
	void deposit(int d) 
	{
		balance += d;
	}
	virtual void withdraw(int w) 
	{
		if (balance - w >= 0)
			balance -= w;
		else
			cout << "insufficient" << endl;
	}
	virtual void print() 
	{
		cout << name << " " << account << " Balance:" << balance << endl;
	}
	virtual ~BaseAccount() 
	{
		if (name != NULL)
			delete name;
		if (account != NULL)
			delete account;
	}
};
class BasePlus :public BaseAccount 
{
protected:
	int limit;
	int limit_sum;
public:
	BasePlus(char* n, char* a, int b) :BaseAccount(n, a, b) 
	{
		limit = 5000;
		limit_sum = 0;
	}
	virtual void withdraw(int w) 
	{
		if (balance - w >= -5000) 
		{
			balance -= w;
			if (balance < 0) 
			{
				limit = 5000 + balance; 	
				limit_sum = balance;
			 
			}
		}
		else
			cout << "insufficient" << endl;
	}
	virtual void print() 
	{
		cout << name << " " << account;
		if (balance < 0)
			cout << " Balance:0";
		else
			cout << " Balance:" << balance;
		cout << " limit:" << limit << endl;
	}
};
int main() 
{
	int t, b, d, w;
	char n[20], a[20];
	cin >> t;
	BaseAccount* p; 
	while (t--) 
	{
		cin >> n >> a >> b;
		if (a[1] == 'A') 
		{
			BaseAccount b1(n, a, b);
			cin >> d >> w;
			p = &b1;	
			p->deposit(d);
			p->withdraw(w);
			cin >> d >> w;
			p->deposit(d);
			p->withdraw(w);
			p->print();
		}
		else 
		{
			BasePlus b1(n, a, b);
			cin >> d >> w;
			p = &b1;
			p->deposit(d);
			p->withdraw(w);
			cin >> d >> w;
			p->deposit(d);
			p->withdraw(w);
			p->print();
		}
	}
}

